var allGagdgetHolders=[];function getGadgetHolder(e){return allGagdgetHolders[e]}function BXGadget(gadgetHolderID,allGadgets){var _this=this;BX.addCustomEvent("onAjaxFailure",(function(e){if(e=="auth"){top.location=top.location.href}}));_this.gadgetHolderID=gadgetHolderID;_this.allGadgets=allGadgets;allGagdgetHolders[_this.gadgetHolderID]=_this;_this.menuItems=[];if(!BX.Type.isUndefined(window.arGDGroups)){for(var gr_id in window.arGDGroups){if(window.arGDGroups.hasOwnProperty(gr_id)){var items=[];for(var _gid in window.arGDGroups[gr_id]["GADGETS"]){if(window.arGDGroups[gr_id]["GADGETS"].hasOwnProperty(_gid)){var gid=window.arGDGroups[gr_id]["GADGETS"][_gid];for(var i in _this.allGadgets){if(_this.allGadgets[i]["ID"].toUpperCase()==gid.toUpperCase()){_this.allGadgets[i]["ONCLICK"]="getGadgetHolder('"+_this.gadgetHolderID+"').Add('"+_this.allGadgets[i]["ID"]+"')";items[items.length]=_this.allGadgets[i];break}}}}}_this.menuItems[gr_id]={ID:gr_id,TEXT:'<div style="text-align: left;"><b>'+window.arGDGroups[gr_id]["NAME"]+"</b><br>"+window.arGDGroups[gr_id]["DESCRIPTION"]+"</div>",MENU:items}}}_this.gdList=Array();_this.gdCols=Array();_this.__GDList=function(){_this.gdList=Array();_this.gdCols=Array();var e=document.getElementById("GDHolder_"+_this.gadgetHolderID).rows[0].cells;var t,i,s,a;for(a=0;a<e.length;a++){if(e[a].id.substring(0,1)=="s"){i=Array();t=e[a].childNodes;for(s in t){if(t.hasOwnProperty(s)){if(!t[s])continue;if(t[s].tagName&&(t[s].tagName.toUpperCase()=="TABLE"||t[s].tagName.toUpperCase()=="DIV")&&t[s].id.substring(0,1)=="t"){i[i.length]=t[s]}}}_this.gdList[_this.gdCols.length]=i;e[a].realPos=jsUtils.GetRealPos(e[a]);_this.gdCols[_this.gdCols.length]=e[a]}}};_this.gdDrag=false;_this.mousePos={x:0,y:0};_this.zind=0;_this.tmpDiv=false;_this.DragStart=function(e,t){if(t){if(t.srcElement&&t.srcElement.tagName.toLowerCase()=="a")return false;if(t.originalTarget&&t.originalTarget.tagName.toLowerCase()=="a")return false}_this.__GDList();var i=BX("t"+e);var s=jsUtils.GetRealPos(i);var a=BX("d"+e);a.style.display="block";a.width=i.offsetWidth+"px";a.style.height=i.offsetHeight+"px";i.style.position="absolute";i.style.width=a.offsetWidth+"px";i.style.height=a.offsetHeight+"px";i.style.border="1px solid #777777";_this.zind=i.style.zIndex;i.style.zIndex="10000";i.style.left=s["left"]+20+"px";i.style.top=s["top"]+"px";i.style.MozOpacity=.6;i.style.opacity=.6;i.style.filter="gray() alpha(opacity=60)";_this.gdDrag=e;_this.tmpDiv=document.createElement("DIV");_this.tmpDiv.style.display="none";_this.tmpDiv.innerHTML="";i.parentNode.insertBefore(_this.tmpDiv,i);document.body.appendChild(i);BX.ZIndexManager.register(i);_this.mousePos.x=t.clientX+document.body.scrollLeft;_this.mousePos.y=t.clientY+document.body.scrollTop;return false};_this.onMouseMove=function(e){if(_this.gdDrag===false)return;var t=document.getElementById("t"+_this.gdDrag);var i=e.clientX+document.body.scrollLeft;var s=e.clientY+document.body.scrollTop;t.style.left=parseInt(t.style.left)+i-_this.mousePos.x+"px";t.style.top=parseInt(t.style.top)+s-_this.mousePos.y+"px";var a=jsUtils.GetRealPos(t),d,r,n,o=false,l;var g=a.left+(a.right-a.left)/2,p=a.top+(a.bottom-a.top)/2;for(r=0;r<_this.gdCols.length;r++){d=_this.gdCols[r].realPos;if(d.left<=g&&d.right>=g){for(n in _this.gdList[r]){if(_this.gdList[r].hasOwnProperty(n)){if(_this.gdList[r][n].id==t.id)l=jsUtils.GetRealPos(document.getElementById("d"+_this.gdDrag));else l=jsUtils.GetRealPos(_this.gdList[r][n]);if(p<l.bottom){o=_this.gdList[r][n];_this.tmpDiv=document.createElement("DIV");_this.tmpDiv.style.display="none";_this.tmpDiv.innerHTML="";if(_this.gdList[r][n].id==t.id)document.getElementById("d"+_this.gdDrag).parentNode.insertBefore(_this.tmpDiv,document.getElementById("d"+_this.gdDrag));else o.parentNode.insertBefore(_this.tmpDiv,o);break}}}if(!o){o="last"}break}}if(o){var h=document.getElementById("d"+_this.gdDrag);h.parentNode.removeChild(h);if(o=="last")_this.gdCols[r].appendChild(h);else _this.tmpDiv.parentNode.insertBefore(h,_this.tmpDiv)}_this.mousePos.x=i;_this.mousePos.y=s};_this.onMouseUp=function(e){if(_this.gdDrag===false)return;var t=BX("t"+_this.gdDrag);t.style.MozOpacity=1;t.style.opacity=1;t.style.filter="";t.style.position="static";t.style.border="0px";t.style.width="";t.style.height="";t.style.zIndex=_this.zind;var i=BX("d"+_this.gdDrag);i.style.display="none";BX.ZIndexManager.unregister(t);t.parentNode.removeChild(t);i.parentNode.insertBefore(t,i);_this.gdDrag=false;if(!_this.sendWait){_this.sendWait=true;setTimeout("getGadgetHolder('"+_this.gadgetHolderID+"').SendUpdatedInfo();",1e3)}};_this.GetPosString=function(){var e=document.getElementById("GDHolder_"+_this.gadgetHolderID).rows[0].cells;var t,i,s;var a="",d=-1,r=0;for(s=0;s<e.length;s++){if(e[s].id.substring(0,1)=="s"){d++;r=0;t=e[s].childNodes;for(i in t){if(t.hasOwnProperty(i)){if(!t[i])continue;if(t[i].tagName&&(t[i].tagName.toUpperCase()=="TABLE"||t[i].tagName.toUpperCase()=="DIV")&&t[i].id.substring(0,1)=="t"){a=a+"&POS["+d+"]["+r+"]="+encodeURIComponent(t[i].id.substring(1))+(t[i].className.indexOf(" gdhided")>0?"*H":"");r++}}}}}return a};_this.GetPos=function(){var e=document.getElementById("GDHolder_"+_this.gadgetHolderID).rows[0].cells;var t,i,s;var a=[],d=-1,r=0;for(s=0;s<e.length;s++){if(e[s].id.substring(0,1)=="s"){d++;r=0;t=e[s].childNodes;for(i in t){if(t.hasOwnProperty(i)){if(!t[i])continue;if(t[i].tagName&&(t[i].tagName.toUpperCase()=="TABLE"||t[i].tagName.toUpperCase()=="DIV")&&t[i].id.substring(0,1)=="t"){if(typeof a[d]=="undefined"){a[d]=[]}a[d][r]=t[i].id.substring(1)+(t[i].className.indexOf(" gdhided")>0?"*H":"");r++}}}}}return a};_this.SendUpdatedInfo=function(e){e=e||"update_position";if(!!_this.sendUpdate||_this.gdDrag!==false){setTimeout("getGadgetHolder('"+_this.gadgetHolderID+"').SendUpdatedInfo('"+e+"');",500);return}_this.sendUpdate=true;_this.sendWait=false;BX.ajax({url:updateURL,method:"POST",dataType:"html",data:{sessid:BX.bitrix_sessid(),gd_ajax:_this.gadgetHolderID,gd_ajax_action:e,POS:_this.GetPos()},onsuccess:function(t){_this.sendUpdate=false;if(e=="clear_settings"){window.location=window.location}},onfailure:function(e){_this.sendUpdate=false;alert(langGDError1)}})};_this.Add=function(e){var t=document.getElementById("GDHolderForm_"+_this.gadgetHolderID);t["gid"].value=e;t["action"].value="add";t.submit()};_this.UpdSettings=function(e){var t=document.getElementById("GDHolderForm_"+_this.gadgetHolderID);t["gid"].value=e;t["action"].value="update";function i(e,i){var s;if(typeof i=="object"||i instanceof Array){for(var a in i){if(i.hasOwnProperty(a)){s=document.createElement("INPUT");s.type="hidden";s.name="settings["+e+"][]";s.value=i[a];t.appendChild(s)}}}else{s=document.createElement("INPUT");s.type="hidden";s.name="settings["+e+"]";s.value=i;t.appendChild(s)}}var s=document.getElementById("dset"+e);var a,d="";for(var r=0;r<s._inputs.length;r++){a=document.getElementById(e+"_"+s._inputs[r]);if(a){if(a.tagName.toUpperCase()=="SELECT"&&a.multiple){var n=[];for(var o=0;o<a.options.length;o++)if(a.options[o].selected)n.push(a.options[o].value);i(s._inputs[r],n)}else if(a.tagName.toUpperCase()=="INPUT"&&a.type.toUpperCase()=="CHECKBOX")i(s._inputs[r],a.checked?"Y":"N");else i(s._inputs[r],a.value)}}t.submit()};_this.SetForAll=function(){langGDConfirm=langGDConfirm1;if(arguments[0]){if(arguments[0]=="SU")langGDConfirm=langGDConfirmUser;if(arguments[0]=="SG")langGDConfirm=langGDConfirmGroup}if(!confirm(langGDConfirm))return;_this.SendUpdatedInfo("save_default")};_this.ClearUserSettings=function(){_this.SendUpdatedInfo("clear_settings")};_this.ClearUserSettingsConfirm=function(){if(!confirm(langGDClearConfirm))return;_this.SendUpdatedInfo("clear_settings")};_this.Delete=function(e){var t=document.getElementById("t"+e);if(t)t.parentNode.removeChild(t);var i=document.getElementById("d"+e);if(i)i.parentNode.removeChild(i);if(!_this.sendWait){_this.sendWait=true;setTimeout("getGadgetHolder('"+_this.gadgetHolderID+"').SendUpdatedInfo();",500)}return false};_this.Hide=function(e,t){var i=document.getElementById("t"+e);if(!i)return;if(i.className.indexOf(" gdhided")>0)i.className="data-table-gadget";else i.className="data-table-gadget gdhided";if(!_this.sendWait){_this.sendWait=true;setTimeout("getGadgetHolder('"+_this.gadgetHolderID+"').SendUpdatedInfo();",500)}return false};_this.CloseSettingsForm=function(e){var t=document.getElementById("dset"+e);t.style.display="none"};BXGadget.prototype.ShowSettings=function(id,t){var dS=document.getElementById("dset"+id);var is_selected="";t=t||"get_settings";_this=this;if(dS.style.display!="none"){dS.style.display="none";return}BX.ajax({url:updateURL,method:"POST",dataType:"html",data:{sessid:BX.bitrix_sessid(),gd_ajax:_this.gadgetHolderID,gid:id,gd_ajax_action:t},onsuccess:function(data){var before=(new Date).getTime();var dSet=document.getElementById("dset"+id);dSet.innerHTML="";dSet._inputs=[];try{eval("var gdObject = "+data)}catch(e){return}var param,param_id;var oEl;for(param_id in gdObject){if(gdObject.hasOwnProperty(param_id)){param=gdObject[param_id];var str="";var input_id=id+"_"+param_id;param["TYPE"]=param["TYPE"]||"STRING";if(!param["VALUE"]&&param["DEFAULT"]!="undefined")param["VALUE"]=param["DEFAULT"];if(param["TYPE"]=="STRING"){str=param["NAME"]+':<br><input type="text" id="'+input_id+'" size="40" value="'+jsUtils.htmlspecialchars(param["VALUE"])+'"><br>'}else if(param["TYPE"]=="LIST"){var aR=[];for(var vid in param["VALUES"]){if(param["VALUES"].hasOwnProperty(vid)){if(param["MULTIPLE"]=="Y"){is_selected="";if(param["VALUE"]instanceof Array){for(var k=0;k<param["VALUE"].length;k++){if(param["VALUE"][k]==vid){is_selected=" selected";break}}}else is_selected=param["VALUE"]==vid?" selected":""}else is_selected=param["VALUE"]==vid?" selected":"";aR.push('<option value="'+vid+'" '+is_selected+">"+param["VALUES"][vid]+"</option>")}}str=param["NAME"]+':<br><select style="width:100%" id="'+input_id+'" '+(param["MULTIPLE"]=="Y"?'multiple="multiple"':"")+">"+aR.join("")+"</select>"}else if(param["TYPE"]=="CHECKBOX"){str=param["NAME"]+': <input type="checkbox" id="'+input_id+'" value="Y" '+(param["VALUE"]=="Y"?" checked":"")+"><br>"}oEl=document.createElement("DIV");oEl.className="gdsettrow";oEl.innerHTML=str;dSet.appendChild(oEl);dSet._inputs[dSet._inputs.length]=param_id}}oEl=document.createElement("DIV");oEl.className="gdsettrow";oEl.innerHTML='<input type="button" value="OK" onclick="getGadgetHolder(\''+_this.gadgetHolderID+"').UpdSettings('"+id+'\');"> <input type="button" value="'+langGDCancel+'" onclick="getGadgetHolder(\''+_this.gadgetHolderID+"').CloseSettingsForm('"+id+"');\">";dSet.appendChild(oEl);dSet.style.display="block"},onfailure:function(e){alert(langGDError2)}});return false};BXGadget.prototype.ShowAddGDMenu=function(e){this.menu=new PopupMenu("gadgets_float_menu");this.menu.Create(1e3);if(this.menu.IsVisible())return;this.menu.SetItems(this.menuItems);this.menu.BuildItems();var t=jsUtils.GetRealPos(e);t["bottom"]+=1;this.menu.PopupShow(t)};jsUtils.addEvent(document.body,"mousemove",_this.onMouseMove);jsUtils.addEvent(document.body,"mouseup",_this.onMouseUp)}
//# sourceMappingURL=script.map.js